package cn.hchaojie.camp.day12;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DemoExecutor {
	public static void main(String[] args) {
		// Executor: 线程执行器
		// 创建一个具有3个线程的线程池
		ExecutorService service = Executors.newFixedThreadPool(1);
		service.execute(new ExecutorRunnable(8));
		service.execute(new ExecutorRunnable(9));
		service.execute(new ExecutorRunnable(10));
		service.execute(new ExecutorRunnable(12));
		service.execute(new ExecutorRunnable(13));
		
		service.shutdown();
	}

}

class ExecutorRunnable implements Runnable {
	private int num;
	public ExecutorRunnable(int num) {
		this.num = num;
	}

	@Override
	public void run() {
		int count = 0;
		try {
			while (count++ < 10) {
				Thread.sleep(500);
				System.out.println(num);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
